import wx
try:
    from agw import ultimatelistctrl as ULC
except ImportError: # if it's not there locally, try the wxPython lib.
    from wx.lib.agw import ultimatelistctrl as ULC


# Main source path for files.
app_path = "D:\\Eigene Datein\\Python\\TIGS DB\\"
source_path = app_path + "files\\"

# Panel 2 - ListCtrl
class ListCtrl(ULC.UltimateListCtrl):
    def __init__(self, parent, data):
        """Listctrl panel for the TIGS data."""
        ULC.UltimateListCtrl.__init__(self, parent, -1,
                                      agwStyle=wx.LC_REPORT|wx.LC_VIRTUAL|
                                      wx.LC_HRULES|wx.LC_VRULES|ULC.ULC_SHOW_TOOLTIPS)
        # Create the columns.
        lables = ["pIPKTA ID", "Tube ID", "Construct function", "Gus cells", "Haustoria",
                  "Experiment name", "Cultivar name", "Hours after inoculation",
                  "Pathogen name", "Link to excel sheet"]
        row = 0
        for lable in lables:
             self.InsertColumn(row, lable)
             self.SetColumnWidth(row, 120)
             row += 1

        # Look and feel
        self.SetItemCount(1000)
        self.attr1 = ULC.UltimateListItemAttr()
        self.attr1.SetBackgroundColour(wx.NamedColour("yellow"))
        self.attr2 = ULC.UltimateListItemAttr()
        self.attr2.SetBackgroundColour(wx.NamedColour("light blue"))


        # Get the requested data.
        self.itemDataMap = data
        self.itemIndexMap = data.keys()
        self.SetItemCount(len(data))

#        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
#        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
#        self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected)
#


#    def OnItemSelected(self, event):
#
#        self.currentItem = event.m_itemIndex
#        self.log.write("OnItemSelected: %s, %s, %s, %s\n" %(self.currentItem,
#                                                          self.GetItemText(self.currentItem),
#                                                          self.getColumnText(self.currentItem, 1),
#                                                          self.getColumnText(self.currentItem, 2)))
#
#    def OnItemActivated(self, event):
#        self.currentItem = event.m_itemIndex
#        self.log.write("OnItemActivated: %s\nTopItem: %s\n" %(self.GetItemText(self.currentItem), self.GetTopItem()))
#
#    def getColumnText(self, index, col):
#
#        item = self.GetItem(index, col)
#        return item.GetText()
#
#    def OnItemDeselected(self, evt):
#        self.log.write("OnItemDeselected: %s\n" % evt.m_itemIndex)


    #---------------------------------------------------
    # Insert data.
    def OnGetItemText(self, item, col):
        index=self.itemIndexMap[item]
        s = self.itemDataMap[index][col]
        return s

    def OnGetItemToolTip(self, item, col):
        return None

    def OnGetItemTextColour(self, item, col):
        return None

    def OnGetItemAttr(self, item):
        return None
#        print item, item % 3
#        if item % 3 == 1:
#            return self.attr1
#        else:
#            return self.attr2



#
#    def OnGetItemColumnCheck(self, item, column):
#
#        if item%3 == 0:
#            return True
#
#        return False
#
#
#    def OnGetItemCheck(self, item):
#
#        if item%3 == 1:
#            return True
#
#        return False
#
#
#    def OnGetItemColumnKind(self, item, column):
#
#        if item%3 == 0:
#            return 2
#        elif item%3 == 1:
#            return 1
#
#        return 0
